package com.heima.wemedia.config;

import com.heima.common.constants.mq.PublishArticleConstants;
import org.springframework.amqp.core.*;
import org.springframework.cloud.client.ConditionalOnBlockingDiscoveryEnabled;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class DeclarePubArticleRabbitConfig  {
    @Bean
    public DirectExchange delayExchange(){
        return ExchangeBuilder
                .directExchange(PublishArticleConstants.DELAY_DIRECT_EXCHANGE)
                .delayed()
                .durable(true).build();
    }
    @Bean
    public Queue publishArticleQueue(){

        return new Queue(PublishArticleConstants.PUBLISH_ARTICLE_QUEUE);
    }
    @Bean
    public Binding bindingDelayQueue(){
        return BindingBuilder
                .bind(publishArticleQueue())
                .to(delayExchange())
                .with(PublishArticleConstants.PUBLISH_ARTICLE_ROUTE_KEY);
    }
}
